from django.db import models
from django.contrib.auth.models import User
from catalogue.models import Foods
from django.utils import timezone
# Create your models here.


class Order(models.Model):
    # 订单所属用户
    user = models.ForeignKey(
        User,
        null=True,
        blank=True,
        on_delete=models.CASCADE,
        related_name='orders',
    )
    # 订单相关的特产
    foods = models.ForeignKey(
        Foods,
        null=True,
        blank=True,
        on_delete=models.CASCADE,
    )
    # 订单号,但不是订单的主键
    oid = models.CharField(max_length=20)
    # 商品数量
    count = models.PositiveIntegerField()
    # 快递方式
    deliver = models.CharField(max_length=10)
    # 订单创建时间
    created = models.DateTimeField(default=timezone.now)
    # 快递地址
    address = models.CharField(max_length=80)
